import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;

//write input file in reverse order in another file

//read file into an array
//write array from end to another file

public class Assignment10 {	
	
	public static void main(String args[]) {	
		String readfileinarray[] = new String[10];
		try{
			FileInputStream ifstream = new FileInputStream("input.txt");
			DataInputStream infile = new DataInputStream(ifstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(infile));
			String ipLine;
			int i = 0;
			while ((ipLine = br.readLine()) != null)   {
				readfileinarray[i] = ipLine;
				i++;
			}
			infile.close();
			FileWriter ofstream = new FileWriter("output.txt");
			BufferedWriter outfile = new BufferedWriter(ofstream);
			//write to file starting from end of array
			for(int j=i-1;j>=0;j--) {
				outfile.write(readfileinarray[j]); 		
				outfile.newLine();
			}
			//Close the output stream
			outfile.close();
		}
		catch (Exception e) {
			System.err.println("Error: ");
			e.printStackTrace();
		}	
	}
}
